using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class ApbtchdtMap : EntityTypeConfiguration<Apbtchdt>
    {
        public ApbtchdtMap()
        {
            // Primary Key
            this.HasKey(t => t.APBTCHDT_ID);

            // Properties
            this.Property(t => t.DESC)
                .HasMaxLength(40);

            this.Property(t => t.REFERENCE)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.BATCH)
                .IsRequired()
                .HasMaxLength(8);

            this.Property(t => t.DRCR)
                .HasMaxLength(1);

            this.Property(t => t.ACCT)
                .IsRequired()
                .HasMaxLength(40);

            this.Property(t => t.SOURCE)
                .HasMaxLength(2);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Apbtchdt");
            this.Property(t => t.APBTCHDT_ID).HasColumnName("APBTCHDT_ID");
            this.Property(t => t.DATE).HasColumnName("DATE");
            this.Property(t => t.AMOUNT).HasColumnName("AMOUNT");
            this.Property(t => t.AMOUNTDOL).HasColumnName("AMOUNTDOL");
            this.Property(t => t.AMOUNTVEND).HasColumnName("AMOUNTVEND");
            this.Property(t => t.DESC).HasColumnName("DESC");
            this.Property(t => t.REFERENCE).HasColumnName("REFERENCE");
            this.Property(t => t.BATCH).HasColumnName("BATCH");
            this.Property(t => t.DRCR).HasColumnName("DRCR");
            this.Property(t => t.JOBID).HasColumnName("JOBID");
            this.Property(t => t.ACCT).HasColumnName("ACCT");
            this.Property(t => t.SOURCE).HasColumnName("SOURCE");
            this.Property(t => t.CURRENCY).HasColumnName("CURRENCY");
            this.Property(t => t.CSTCTRID).HasColumnName("CSTCTRID");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");

            // Relationships
            this.HasRequired(t => t.Acct1)
                .WithMany(t => t.Apbtchdts)
                .HasForeignKey(d => d.ACCT);
            this.HasRequired(t => t.Apbatch)
                .WithMany(t => t.Apbtchdts)
                .HasForeignKey(d => d.REFERENCE);
            this.HasRequired(t => t.Batchttl)
                .WithMany(t => t.Apbtchdts)
                .HasForeignKey(d => d.BATCH);
            this.HasOptional(t => t.Cstctr)
                .WithMany(t => t.Apbtchdts)
                .HasForeignKey(d => d.CSTCTRID);
            this.HasOptional(t => t.Job)
                .WithMany(t => t.Apbtchdts)
                .HasForeignKey(d => d.JOBID);

        }
    }
}
